<?php
    require_once 'php/include.php';
    sys_createHead("Kevin Siegerth","Development Framework");       
?>
<body>
    <header>
        <?php con_createNavigation() ?> 
    </header>

    <section class="title">
        <h1><?php echo con_createPageTitle($_GET['id']) ?></h1>
        <aside>
            <?php con_createLogin() ?>
        </aside>
    </section>
    <footer>
        <p>Breadcrumb <span class="important">:: TO BE DONE</span></p>
    </footer>
    <section id="content" role="main">

<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="post" enctype="multipart/form-data">
    Datei: <br>
    <input type="hidden" name="MAX_FILE_SIZE" value="300000" />
    <input type="file" name="datei" ><br>
    <input type="submit" value="hochladen"/>
</form>


<?php
	con_preFormat($_FILES);
	if(isset($_FILES['datei']) AND ! $_FILES['datei']['error'] AND ($_FILES['datei']['size'] < 300000)) {
	$bildinfo = getimagesize($_FILES['datei']['tmp_name']);
    if ($bildinfo === false) {
    	die ("kein Bild");
    } else {
    	$mime = $bildinfo['mime'];
        $mimetypen = array(
            "image/jpeg" => "jpg",
            "image/gif" => "gif",
            "image/png" => "png"
            );
        if (!isset($mimetypen[$mime])) {
        	die ("nicht das richtige Format");
        } else {
        	$endung = $mimetypen[$mime];
        }
        $neuername = basename($_FILES['datei']['name']);
        $neuername = preg_replace("/\.(jpe?g|gif|png)$/i", "", $neuername);
        $neuername = preg_replace("/[^a-zA-Z0-9_-]/", "", $neuername);
        $neuername .= ".$endung";
        
        $ziel = "img/$neuername";
        while (file_exists($ziel)) {
	        $neuername = "kopie_$neuername";
    	    $ziel = "img/$neuername";
        }
        if (@move_uploaded_file($_FILES['datei']['tmp_name'], $ziel)) {
        	echo "Erfolgreich";
        } else {
        	echo "Fehler";
        }
    }
}?>


    </section><?php //CONTENT DIV end ?>
    <footer>
        <?php con_createFooter() ?>
    </footer>
    <?php sys_includeAdditionalScripts() //MEANT FOR jQUERY or ELSE ?>
    <?php if(!empty($message)){echo $message;}?>
</body>
</html>